//
//  ExpertDetailsExpertProperty.m
//
//  Created by 啊  on 16/5/10
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "ExpertDetailsExpertProperty.h"


NSString *const kExpertDetailsExpertPropertyEId = @"eId";
NSString *const kExpertDetailsExpertPropertyEpType = @"epType";
NSString *const kExpertDetailsExpertPropertyEpExpand = @"epExpand";


@interface ExpertDetailsExpertProperty ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ExpertDetailsExpertProperty

@synthesize eId = _eId;
@synthesize epType = _epType;
@synthesize epExpand = _epExpand;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.eId = [[self objectOrNilForKey:kExpertDetailsExpertPropertyEId fromDictionary:dict] doubleValue];
            self.epType = [self objectOrNilForKey:kExpertDetailsExpertPropertyEpType fromDictionary:dict];
            self.epExpand = [self objectOrNilForKey:kExpertDetailsExpertPropertyEpExpand fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.eId] forKey:kExpertDetailsExpertPropertyEId];
    [mutableDict setValue:self.epType forKey:kExpertDetailsExpertPropertyEpType];
    [mutableDict setValue:self.epExpand forKey:kExpertDetailsExpertPropertyEpExpand];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.eId = [aDecoder decodeDoubleForKey:kExpertDetailsExpertPropertyEId];
    self.epType = [aDecoder decodeObjectForKey:kExpertDetailsExpertPropertyEpType];
    self.epExpand = [aDecoder decodeObjectForKey:kExpertDetailsExpertPropertyEpExpand];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeDouble:_eId forKey:kExpertDetailsExpertPropertyEId];
    [aCoder encodeObject:_epType forKey:kExpertDetailsExpertPropertyEpType];
    [aCoder encodeObject:_epExpand forKey:kExpertDetailsExpertPropertyEpExpand];
}

- (id)copyWithZone:(NSZone *)zone
{
    ExpertDetailsExpertProperty *copy = [[ExpertDetailsExpertProperty alloc] init];
    
    if (copy) {

        copy.eId = self.eId;
        copy.epType = [self.epType copyWithZone:zone];
        copy.epExpand = [self.epExpand copyWithZone:zone];
    }
    
    return copy;
}


@end
